Choose the hat you want to replace and extract the folders inside into your team fortress 2/tf/ folder, usually located in
C:\Program Files\Steam\steamapps\your username\team fortress 2

Also note that this needs the items_game.txt file in the scripts\items folder to change the hat it replaces so it doesn't fall off on death. Whenever the game updates, it may delete the file. The replacement works without it, though it won't be quite as pretty. 

If you already have an edited items_game file, you should not replace it, but instead open it and edit the file yourself to make sure the hat works properly. You can do this by finding the hat you want to edit and change "drop type" "drop" to read "drop type" "none"

If you replaced a hat that is shared by many classes, such as the gibus, then the drop type change affects the gibus of every class.